<template>
  <div>
    <h1 style="font-size: 50px">添加分类</h1>
    <van-field label="分类名称" v-model="form.name"></van-field>
    <van-button @click="addcate" round>添加</van-button>
    <h1 style="font-size: 50px">添加商品</h1>
    <van-field label="商品名称" v-model="form1.name"></van-field>
    <select name="" id="" v-model="form1.cid">
      <option :value="i.id" v-for="i in cate">{{ i.name }}</option>

    </select>
    <van-button @click="addshop" round>添加</van-button>
  </div>
</template>

<script>
export default {
  name: "qcate",
  data() {
    return {
      form: {},
      form1: {},
      cate: []
    }
  },
  methods: {
    addcate() {
      this.$axios.post('/qcate/cate', this.form)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.form = {}
          }
        })

    },
    addshop() {
      this.$axios.post('/qcate/shop', this.form1)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.form1 = {}
          }
        })
    },
    getcate() {
      this.$axios.get('/qcate/cate')
        .then(res => {
          this.cate = res.data.list
        })
    }
  },
  mounted() {
    this.getcate()
  }
}
</script>

<style scoped>

</style>
